package com.payment.web.controller.system;

import java.util.List;

import com.payment.system.service.ICardTypeService;
import com.payment.system.service.IIssBankService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.payment.common.annotation.Log;
import com.payment.common.enums.BusinessType;
import com.payment.system.domain.CardBin;
import com.payment.system.service.ICardBinService;
import com.payment.framework.web.base.BaseController;
import com.payment.common.page.TableDataInfo;
import com.payment.common.base.AjaxResult;
import com.payment.common.utils.ExcelUtil;

/**
 * 卡bin维护 信息操作处理
 * 
 * @author payment
 * @date 2018-12-27
 */
@Controller
@RequestMapping("/system/cardBin")
public class CardBinController extends BaseController
{
    private String prefix = "system/cardBin";
	
	@Autowired
	private ICardBinService cardBinService;
	@Autowired
	private IIssBankService issBankService;
	@Autowired
	private ICardTypeService cardTypeService;
	@RequiresPermissions("system:cardBin:view")
	@GetMapping()
	public String cardBin()
	{
	    return prefix + "/cardBin";
	}
	
	/**
	 * 查询卡bin维护列表
	 */
	@RequiresPermissions("system:cardBin:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CardBin cardBin)
	{
		startPage();
        List<CardBin> list = cardBinService.selectCardBinList(cardBin);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出卡bin维护列表
	 */
	@RequiresPermissions("system:cardBin:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CardBin cardBin)
    {
    	List<CardBin> list = cardBinService.selectCardBinList(cardBin);
        ExcelUtil<CardBin> util = new ExcelUtil<CardBin>(CardBin.class);
        return util.exportExcel(list, "cardBin");
    }
	
	/**
	 * 新增卡bin维护
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("bank",issBankService.selectIssBankAll());
		mmap.put("cardType",cardTypeService.selectCardTypeAll());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存卡bin维护
	 */
	@RequiresPermissions("system:cardBin:add")
	@Log(title = "卡bin维护", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(CardBin cardBin)
	{		
		return toAjax(cardBinService.insertCardBin(cardBin));
	}

	/**
	 * 修改卡bin维护
	 */
	@GetMapping("/edit/{iD}")
	public String edit(@PathVariable("iD") String iD, ModelMap mmap)
	{
		CardBin cardBin = cardBinService.selectCardBinById(iD);
		mmap.put("cardBin", cardBin);
		mmap.put("bank",issBankService.selectIssBankAll());
		mmap.put("cardType",cardTypeService.selectCardTypeAll());
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存卡bin维护
	 */
	@RequiresPermissions("system:cardBin:edit")
	@Log(title = "卡bin维护", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(CardBin cardBin)
	{		
		return toAjax(cardBinService.updateCardBin(cardBin));
	}
	
	/**
	 * 删除卡bin维护
	 */
	@RequiresPermissions("system:cardBin:remove")
	@Log(title = "卡bin维护", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(cardBinService.deleteCardBinByIds(ids));
	}
	
}
